//index.js
//获取应用实例
const app = getApp()

var config = require('../../config/config'),
	util = require('../../utils/util'),
	chart = require('../../utils/wxcharts-min')

Page({
	data: {
		userInfo: {},
		coins: ''
	},

	onLoad: function() {
		let userInfo = wx.BaaS.storage.get('userinfo')
		if(userInfo) {
			this.setData({
				userInfo: userInfo
			})

			let coins = wx.BaaS.storage.get('coins')
			if(coins) {
				this.setData({
					coins: ' (金币:' + coins + ')'
				})
			}
		}
	},

	//显示
	onShow: function() {
		let userInfo = this.data.userInfo
		if(userInfo) {
			this.setData({
				userInfo: userInfo
			})

			let coins = wx.BaaS.storage.get('coins')
			if(coins) {
				this.setData({
					coins: ' (金币:' + coins + ')'
				})
			}
		}
	},
  //心跳动画
  xintiao: function (circleCount, rate) {
    // 心跳的外框动画
    this.xin = wx.createAnimation({
      duration: 1000, // 以毫秒为单位
      timingFunction: 'linear',
      delay: 10,
      transformOrigin: '50% 50%',
      success: function (res) {
      }
    });

    setInterval(function () {
      if (circleCount % 2 == 0) {
        this.xin.scale(rate).step();
      } else {
        this.xin.scale(1.0).step();
      }
      this.setData({
        xin: this.xin.export()
      });
      circleCount++;
      if (circleCount == 1000) {
        circleCount = 0;
      }
    }.bind(this), 1000);
  },
  //跳转help
  toHelp: function () {
    let that = this
    wx.showModal({
      title: '温馨提示',
      content: '是否显示帮助？',
      showCancel: true,
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({ url: '/pages/index/help?uid=' + that.data.userInfo.id })
          console.log('/pages/index/help?uid=' + that.data.userInfo.id)
        } else if (res.cancel) {
          // wx.navigateTo({ url: '/pages/long/add' })
        }
      }
    })
  },

  //跳转金币日志
  ToCoinLog: function () {
    let userInfo = this.data.userInfo
    wx.navigateTo({ url: '/pages/pay/coin_log?uid=' + this.data.userInfo.id })
  },
})